package com.ss.android.common.location;

import android.content.Context;
import android.telephony.CellLocation;
import android.telephony.NeighboringCellInfo;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;
import java.util.List;

public final class BaseStationHelper {
    private final TelephonyManager mTelephonyManager;

    public BaseStationHelper(Context arg2) {
        this.mTelephonyManager = (TelephonyManager) arg2.getSystemService(Context.TELEPHONY_SERVICE);
    }

    private static void addNeighboringCellInfo(JSONObject arg6, List arg7) {
        if (arg7 != null) {
            JSONArray v1 = new JSONArray();
            Iterator v2 = arg7.iterator();
            while (v2.hasNext()) {
                Object v0 = v2.next();
                if (v0 == null) {
                    continue;
                }

                JSONObject v3 = new JSONObject();
                try {
                    v3.put("cid", ((NeighboringCellInfo) v0).getCid());
                    v3.put("psc", ((NeighboringCellInfo) v0).getPsc());
                    v3.put("lac", ((NeighboringCellInfo) v0).getLac());
                    v3.put("type", ((NeighboringCellInfo) v0).getNetworkType());
                    v3.put("rssi", ((NeighboringCellInfo) v0).getRssi());
                } catch (JSONException v0_1) {
                }

                v1.put(v3);
            }

            try {
                arg6.put("neighboring", v1);
            } catch (JSONException v0_1) {
            }
        }
    }

    public final JSONObject getBaseStationData() {
        String v3;
        JSONObject v2;
        JSONObject v1 = new JSONObject();
        if (this.mTelephonyManager != null) {
            try {
                CellLocation v0_1 = this.mTelephonyManager.getCellLocation();
                v2 = new JSONObject();
                if ((v0_1 instanceof GsmCellLocation)) {
                    try {
                        v3 = "type";
                        v2.put(v3, "gsm");
                        v2.put("cid", ((GsmCellLocation) v0_1).getCid());
                        v2.put("lac", ((GsmCellLocation) v0_1).getLac());
                        v2.put("psc", ((GsmCellLocation) v0_1).getPsc());
                    } catch (JSONException v0_2) {
                    }
                } else if (v0_1 instanceof CdmaCellLocation) {
                    try {
                        v3 = "type";
                        v2.put(v3, "cdma");
                        v2.put("bid", ((CdmaCellLocation) v0_1).getBaseStationId());
                        v2.put("lat", ((CdmaCellLocation) v0_1).getBaseStationLatitude());
                        v2.put("long", ((CdmaCellLocation) v0_1).getBaseStationLongitude());
                        v2.put("nid", ((CdmaCellLocation) v0_1).getNetworkId());
                        v2.put("sid", ((CdmaCellLocation) v0_1).getSystemId());
                    } catch (JSONException v0_2) {
                    }
                }

                try {
                    label_22:
                    v1.put("current", v2);
                } catch (JSONException v0_2) {
                }

                addNeighboringCellInfo(v1, this.mTelephonyManager.getNeighboringCellInfo());
            } catch (SecurityException v0) {
            }
        }
        return v1;
    }
}

